package com.wlcj.www.aop;

import java.sql.SQLException;

import org.nutz.aop.InterceptorChain;
import org.nutz.ioc.loader.annotation.IocBean;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.IAtom;

@IocBean(name="tx")
public class TxInterceptor implements org.nutz.aop.MethodInterceptor {

	@Override
	public void filter(final InterceptorChain chain) throws Throwable {
		Db.tx(new IAtom() {
			@Override
			public boolean run() throws SQLException {
				try {
					System.out.println("aop before...");
					chain.doChain();
					System.out.println("aop after...");
				} catch (Throwable e) {
					throw new RuntimeException(e);
				}
				return true;
			}
		});
	}

}
